package structural.proxy.dynamic_proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName: SubjectJDKProxy
 * @Description: 代理工厂
 * @Author: liu-hao
 * @Date: 2023-04-09 21:51
 * @Version: 1.0
 **/
public class ProxyFactory {

    /**
     * 获取动态代理的对象
     *
     * @param obj 被代理类的对象
     * @return
     */
    public static Object getProxyInstance(Object obj) {
        Class clazz = obj.getClass();
        MyInvocationHandler handler = new MyInvocationHandler(obj);
        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), handler);
    }
}
